--#include "data\config\fuben\SbkFubenConfig.lua" once
--#include "data\functions\Common\CommonFunc.lua" once


--[[
注册一些事件
]]
function ResisterSbkFubenProc()
	--print("ResisterPersonBossProc...")
	--[[
	for fubenIdx, fubenConfig in ipairs( SbkFubenConfig ) do
		SceneEnterDispatcher.register( fubenConfig.sceneId, OnEnterSbkFuben )				--注册进入场景、副本后触发的事件
	end
	]]
	SceneEnterDispatcher.register( SbkFubenConfig[2].sceneId, OnEnterSbkFuben )				--注册进入场景、副本后触发的事件
	SceneExitDispatcher.register( SbkFubenConfig[2].sceneId, OnExitSbkFuben )	
end

function OnEnterSbkFuben( sysarg, sceneId, lastSceneId )
	local fubenId = Actor.getFubenId( sysarg )
	local fubenCfg = SbkFubenConfig[2]			--只管第2个场景
	if fubenId == fubenCfg.fubenId then				
		--print("OnEnterSbkFuben, fubenId="..fubenCfg.fubenId)
		FreshSbkFubenMonster( sysarg, fubenCfg.monsters )
		--OpenCommonBossPanel( sysarg, 1, enRightPanelActivity_SbkFuben, Lang.ScriptTips.SbkFubenName, fubenCfg, {1}, nil, GetCommonBossMonsterNum2 )

		local title 	= Lang.ScriptTips.SbkFubenName
		local contStyle = 3
		local buttons 	= {1}
		OpenCommonStylePanel( sysarg, 1, enRightPanelActivity_SbkFuben, 0, title, fubenCfg, contStyle, buttons  )
	end
end

--[[
退出个人BOSS副本
注意：手工退出、下线、被T出，GM指令Move出都会触发
]]
function OnExitSbkFuben( sysarg, sceneId, fubenId )
	--print("OnExitSbkFuben, sceneId="..sceneId..", fubenId="..fubenId)
	CloseActivityRightPanel(sysarg)				--关闭面板
end

--[[
进入沙巴克体验副本
]]
function EnterSbkFuben( sysarg )
	--print("EnterPersonBoss, bossIdx="..bossIdx)
	local fubenCfg = SbkFubenConfig[1]
	if not fubenCfg then
		return
	end

	if CommonEnterScence( sysarg, fubenCfg, 0, "" ) then
		FreshSbkFubenMonster( sysarg, fubenCfg.monsters )
		--OpenCommonBossPanel( sysarg, 1, enRightPanelActivity_SbkFuben, Lang.ScriptTips.SbkFubenName, fubenCfg, {1}, nil, GetCommonBossMonsterNum2 )
		local title 	= Lang.ScriptTips.SbkFubenName
		local contStyle = 3
		local buttons 	= {1}
		OpenCommonStylePanel( sysarg, 1, enRightPanelActivity_SbkFuben, 0, title, fubenCfg, contStyle, buttons  )


		if fubenCfg.enterMovieId and fubenCfg.enterMovieId > 0 then
			Actor.triggerPictureGuide( sysarg, fubenCfg.enterMovieId )
		end
	end
end


function FreshSbkFubenMonster( sysarg, monsters )
	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local fubenHandle 	= Fuben.getFubenHandle(fubenPtr)
	FreshCommonMonsters( monsters, fubenHandle )
end

--个人boss被击杀
--sysarg:归属玩家
--lastHitKiller：最后一击玩家
function OnSbkFubenMonsterDie(monster, sysarg, monId, lastHitKiller)
	local sceneId = Actor.getSceneId( sysarg )
	local fubenCfg = GetSbkFubenCfgBySceneId( sceneId )
	if not fubenCfg then
		return
	end
	--ChangeCommonBossPanel( sysarg, fubenCfg, {1}, {1}, nil, GetCommonBossMonsterNum2 )

	local sts = 1
	local contStyle = 3
	ChangeCommonStylePanel( sysarg, sts, contStyle, fubenCfg, {1}, {1} )

	local fubenPtr 		= Actor.getFubenPrt(sysarg)
	local fubenHandle	= Fuben.getFubenHandle(fubenPtr)
	local allBoss, killBoss, allMon, killMon = GetCommonBossMonsterNum6( fubenHandle, fubenCfg.monsters )
	if killMon >= allMon then
		local nextFubenIdx = fubenCfg.fubenIdx+1
		local nextFubenCfg = SbkFubenConfig[nextFubenIdx]
		if nextFubenCfg then			--进入副本的下一个场景
			DoCommonEnterScence( sysarg, nextFubenCfg, 0, "" )
		else 							--10秒后退出副本
			--LocalDT.ScriptDelayConfig中配置的延迟消息
			if fubenCfg.quitCountDownTime and fubenCfg.quitCountDownTime > 0 then
				--print("OnSbkFubenMonsterDie, quitCountDownTime="..fubenCfg.quitCountDownTime)
				Actor.postEntityScriptDelayMsg(sysarg, fubenCfg.quitCountDownTime*1000, 0, 16,0,0,0,0,false)
				local boardStr = Lang.ScriptTips.COM0054				--注意：字符串中要带有一个 %d
				OpenBoardPanel( sysarg, enBoardPanelStyle_CountDown1, boardStr, fubenCfg.quitCountDownTime )
			end

			if fubenCfg.teleport and fubenCfg.teleport.passVisible then
				local hScene = Actor.getSceneHandle(sysarg)
				System.setTeleportVisible( true, hScene, fubenCfg.teleport.posx, fubenCfg.teleport.posy )
			end

			if fubenCfg.allMonsterDieMovieId and fubenCfg.allMonsterDieMovieId > 0 then
				Actor.triggerPictureGuide( sysarg, fubenCfg.allMonsterDieMovieId )
			end
		end
	end
end


function GetSbkFubenCfgBySceneId( sceneId )
	for i, fubenCfg in ipairs( SbkFubenConfig ) do
		if fubenCfg.sceneId == sceneId then
			return fubenCfg
		end
	end
	return nil
end

function GetSbkFubenCfgByFubenId( fubenId )
	for i, fubenCfg in ipairs( SbkFubenConfig ) do
		if fubenCfg.fubenId == fubenId then
			return fubenCfg
		end
	end
	return nil
end


function IsInSbkFuben( fubenId )
	for i, fubenCfg in ipairs( SbkFubenConfig ) do
		if fubenCfg.fubenId == fubenId then
			return true
		end
	end
	return false
end

function IsInSbkFubenScene( sceneId )
	--print("IsInPersonBossScene, sceneId="..sceneId)
	for i, fubenCfg in ipairs( SbkFubenConfig ) do
		if fubenCfg.sceneId == sceneId then
			return true
		end
	end
	return false
end

ResisterSbkFubenProc()
